package com.ay.controller;


import com.ay.entity.Item;
import com.ay.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;

@Controller
public class ItemController {

    @Autowired
    ItemService itemService;

    @RequestMapping("/find")
    @ResponseBody
    public Item findById(@RequestParam Integer id){


        Item item = itemService.findById(id);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        System.out.println( sdf.format(item.getCreattime()));
        item.setStrcreattime(  sdf.format(item.getCreattime()));

        System.out.println(item.getStrcreattime());
        return item;
    }

    @RequestMapping("/test")
    @ResponseBody
    public void test(){
        System.out.println(11);
    }

    @RequestMapping("/save")
    @ResponseBody
    public int save(@RequestBody Item item){
        System.out.println(item);
        System.out.println(item.getCreattime());

        itemService.save(item);
        return  1;
    }

}
